package cn.itcast.hotel.Config;

import cn.itcast.hotel.Contants.MqConstants;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 配置交换机，队列，还有绑定关系
 */
@Configuration
public class MqConfig {
    @Bean
    public TopicExchange exchange(){
        return new TopicExchange(MqConstants.EXCHANGE_HOTEL, true, false);
    }
    @Bean
    public Queue insertQueue() {
        return new Queue(MqConstants.QUEUE_HOTEL_INSERT, true);
    }
    @Bean
    public Queue deleteQueue(){
        return new Queue(MqConstants.QUEUE_HOTEL_DELETE, true);
    }
    @Bean
    public Binding insertBinding(){
        return BindingBuilder.bind(insertQueue()).to(exchange()).with(MqConstants.ROUTING_KEY_HOTEL_INSERT);
    }
    @Bean
    public Binding deleteBinding(){
        return BindingBuilder.bind(deleteQueue()).to(exchange()).with(MqConstants.ROUTING_KEY_HOTEL_DELETE);
    }
}
